{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "4e30cda6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy\n",
    "import pandas"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "76a68d9c",
   "metadata": {},
   "source": [
    "# pandas中的数学函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4edae7e3",
   "metadata": {},
   "source": [
    "- count() 非空值的数量\n",
    "- max() 最大值\n",
    "- min() 最小值\n",
    "- mediam() 中位数\n",
    "- sum() 求和\n",
    "- mean() 平均值\n",
    "---\n",
    "- value_counts() 统计元素出现的个数\n",
    "- cumsum() 累加\n",
    "- cumprod() 累乘\n",
    "- std() 标准差\n",
    "- var() 方差\n",
    "- cov() 协方差\n",
    "- corr() 所有属性相关性系数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b316ad1e",
   "metadata": {},
   "source": [
    "- 相关系数r\n",
    "    - 相关系数 = X与Y的协方差 / (X的标准差 * Y的标准差)\n",
    "    - 相关系数范围在-1到1之间\n",
    "    - r大于0为正相关，r小于0为负相关，r等于0表示不相关\n",
    "    - r的绝对值越大，相关程度越高"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "b3b42d84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>26</td>\n",
       "      <td>50</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>51</td>\n",
       "      <td>62</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>98</td>\n",
       "      <td>48</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    0   1   2\n",
       "0  26  50   1\n",
       "1  51  62  43\n",
       "2  98  48  16"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df = pandas.DataFrame(data=numpy.random.randint(0,100,size=(3,3)))\n",
    "display(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "58a8c1d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0.184436\n",
       "1    0.881121\n",
       "2    1.000000\n",
       "dtype: float64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corrwith(df[2]) # 单一特征相关系数"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
